package secondStage.part3.Set.自然排序Comparable的使用;

import java.util.Comparator;

/**
 * @ClassName: [Student]
 * @Description: 学生类
 * @Author: [黄劲松]
 * @CreateDate: [2021-04-02]
 * @Version: [v1.0]
 */
public class Student implements Comparable<Student> {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Student s) {
//        return 0;//认为是重复元素，不再添加
//        return 1;//按照升序顺序输出
//        return -1;//按照降序顺序输出
        //按照年龄从大到小输出
//        int num = s.age-this.age ;
        //按照年龄从小到大输出
        int num = this.age - s.age;
        int num2 = num == 0 ? this.name.compareTo(s.name) : num;
        return num2;
    }
}
